package com.cc.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class UrlInterceptor implements HandlerInterceptor{
	
	private static String HEADER_ID_INDEX = "index"; //我的工作台
	private static String HEADER_ID_TOUCHPOINT = "touchpoint"; //触点管理
	private static String HEADER_ID_PROJECT = "project"; //项目信息
	private static String HEADER_ID_ASSESSMENT = "assessment"; //考核管理
	private static String HEADER_ID_SEARCH = "search"; //统计查询
	private static String HEADER_ID_KNOWLEDGE = "knowledge"; //知识库管理
	private static String HEADER_ID_SYSTEM = "system"; //系统设置
	private static String HEADER_ID = "header_Identification";//参数标识

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object obj, Exception e)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView mv)
			throws Exception {
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
		int header_index = -1;
		String header_id = request.getParameter(HEADER_ID);
		if(HEADER_ID_INDEX.equals(header_id)) {
			header_index = 0;
		}else if(HEADER_ID_TOUCHPOINT.equals(header_id)) {
			header_index = 1;
		}else if(HEADER_ID_PROJECT.equals(header_id)) {
			header_index = 2;
		}else if(HEADER_ID_ASSESSMENT.equals(header_id)) {
			header_index = 3;
		}else if(HEADER_ID_SEARCH.equals(header_id)) {
			header_index = 4;
		}else if(HEADER_ID_KNOWLEDGE.equals(header_id)) {
			header_index = 5;
		}else if(HEADER_ID_SYSTEM.equals(header_id)) {
			header_index = 6;
		}
		if(header_index!=-1) {
			request.getSession().setAttribute(HEADER_ID, header_index);
		}
		return true;
	}

}
